--POUR CONTROLE


define erp='erp_mli2.';
define outils='outils_mli2.';

DROP TABLE se_gam_section;

CREATE TABLE se_gam_section AS (SELECT * FROM &erp.gam_section WHERE 1=2);








 INSERT INTO se_gam_section

    (SELECT  id section_cod,
             0 enreg_id,
             'N' enreg_s,
             libelle section_lib,
             NULL section_lib2,
             1 rebut_coef
        FROM uv_psections s
        ) ;


 UPDATE se_gam_section tf SET enreg_id=(select enreg_id FROM &erp.gam_section f WHERE f.section_cod=tf.section_cod) ;
 UPDATE se_gam_section tf SET enreg_id=&outils.enreg_id.NEXTVAL WHERE enreg_id IS NULL OR enreg_id =0;



 CALL uvse_synchroverserp('section_cod','GAM_SECTION','O') ;

 commit;
 
 
select * from (
SELECT &outils.stragg(source) source, section_cod, enreg_id, enreg_s, section_lib, section_lib2, rebut_coef
FROM (
  SELECT 'uv' source ,g.* FROM se_gam_section g
  UNION ALL
  SELECT 'se' source ,g.* FROM &erp.gam_section g

  )
GROUP BY section_cod, enreg_id, enreg_s, section_lib, section_lib2, rebut_coef
HAVING Count(1)!=2) r
ORDER BY  section_cod;